<?php
/**
* @package   auto_occasion
* @subpackage essais
* @author    your name
* @copyright 2011 your name
* @link      http://www.yourwebsite.undefined
* @license    All rights reserved
*/


/**
 * Classe pour la gestion des super bof
 */
class BoModeleSuperBofCtrl extends jController {
    
public $pluginParams = array(
        '*' => array('auth.required' => true),
     );
    
    /**
    * Affiche la gestion du superbof (inconvenient / avantage)
    */
    function index() {

		jClasses::inc('essais~essaisSrv') ;
		jClasses::inc('essais~superbofSrv') ;
		jClasses::inc("commun~common");

		$iEssaiId = $this->intParam('iId') ;
		$iApprecId = $this->intParam('id') ;


		$toParams['oEssai'] = ($iEssaiId) ? essaisSrv::getById($iEssaiId) : common::init('ao_essais') ;
		$toParams['superbofDetail'] = ($iEssaiId) ? superbofSrv::chargeParEssaiId($iEssaiId) : array(common::init('ao_appreciation')) ;
        
        if ($iEssaiId) {
            $filename  = JELIX_APP_WWW_PATH . PATH_ESSAI_SUPERBOF . 'guide' . $iEssaiId . '/' . $toParams['superbofDetail'][0]->apprec_plus;
            $filename2 = JELIX_APP_WWW_PATH . PATH_ESSAI_SUPERBOF . 'guide' . $iEssaiId . '/' . $toParams['superbofDetail'][0]->apprec_moins;
            jClasses::inc('commun~toolsFile');

            if (file_exists($filename)) {
                $toParams['superbofDetail'][0]->apprec_plus = str_replace('-', '<br />-', toolsFile::get($filename));
            }
            if (file_exists($filename2)) {
                $toParams['superbofDetail'][0]->apprec_moins = str_replace('-', '<br />-', toolsFile::get($filename2));
            }
        }

		
        $rep = $this->getResponse('html');
        $rep->menusActifs = adminHtmlResponse::MENU_FICHES_GAMMES ;

        $rep->bodyTpl = 'essais~BoModeleSuperBof';
        $rep->body->assignZone ('oZoneModeleLeft', 'essais~BoModeleLeft', array('iId' => $iEssaiId)) ;
		$rep->body->assign($toParams) ;

        return $rep;
    }

	    /**
    * Affiche la gestion du superbof (inconvenient / avantage)
    */
    function save() {

        $rep = $this->getResponse('redirect');
        $iId = $this->intParam('iId');

        jClasses::inc('essais~superbofSrv');
		jClasses::inc("commun~common");
		
		$toParams = $this->params() ;
        if ($toParams['id']) {
            superbofSrv::modifier($toParams);
        } else {
            superbofSrv::ajouter($toParams);
        }
        
        $rep->action = 'essais~BoModeleSuperBof:index';
        $rep->params = array('iId' => $iId) ;

        return $rep;

    }



}